package com.siti.kindnessplatform.view.biz;

import com.siti.kindnessplatform.common.CommonResult;
import com.siti.kindnessplatform.config.EasyCache;
import com.siti.kindnessplatform.view.mapper.ViewMapper;
import com.siti.kindnessplatform.view.vo.ViewAndEncourageVo;
import org.redisson.api.RAtomicLong;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


@Service
public class ViewBiz {

    @Resource
    ViewMapper viewMapper;

    @Resource
    EasyCache easyCache;

    public static final String VIEWCOUNT="viewcount";

    public static final String INDEX_LIKE_WITHOUT_NAME="index_like";


    public CommonResult viewToDb() {
        RedissonClient redisson = easyCache.redisson;
        RAtomicLong num = redisson.getAtomicLong(VIEWCOUNT);
        RAtomicLong indexName = redisson.getAtomicLong(INDEX_LIKE_WITHOUT_NAME);
        long sunEncourage=viewMapper.selectEncourageNum()+indexName.get();
        return new CommonResult("success","请求成功",new ViewAndEncourageVo(){
            {
                setEncourage(sunEncourage);
                setView(num.get());
            }
        });
    }



}
